{extend name="public:layout" /}
{block name="title"}添加字段{/block}
{block name="head"}{/block}
{block name="body"}
<div class="wrapper wrapper-content">
    <div class="ibox">
        <div class="ibox-title">
            <ol class="breadcrumb">
                <li><i class="fa fa-hand-o-right"></i> <a href="{:url('CmsMoudle/index')}"> 模型管理</a></li>
                <li><a href="{:url('index',['mid'=>$moudleInfo['mid']])}"> 字段列表</a></li>
                <li class="active">添加字段</li>
            </ol>
        </div>
        <div class="ibox-content">
            <form method="post" class="form-horizontal" id="form">
                <input type="hidden" name="mid" value="{$moudleInfo.mid}"/>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">字段标题</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" placeholder="请输入字段标题"
                               name="title" datatype="*"/>
                    </div>
                    <label class="col-sm-2 control-label Validform_label">字段类型</label>
                    <div class="col-sm-4">
                        <select name="field_type" id="fieldType" class="form-control">
                            <option value="input">单行文本</option>
                            <option value="box">选项</option>
                            <option value="number">数字框</option>
                            <option value="textarea">多行文本</option>
                            <option value="datetime">日期与时间</option>
                            <option value="editor">富文本</option>
                            <option value="image">单图上传</option>
                            <option value="images">多图上传</option>
                            <option value="file">附件上传</option>
                            <!--<option value="files">多附件上传</option>-->
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">归属表</label>
                    <div class="col-sm-4">
                        <label class="radio-inline i-checks">
                            <input type="radio" name="table_type" value="1" checked/> 主表
                        </label>
                        <label class="radio-inline i-checks">
                            <input type="radio" name="table_type" value="2"/> 附表
                        </label>
                    </div>
                    <label class="col-sm-2 control-label Validform_label">字段名</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" placeholder="必须以字母开头，只能使用字母、数字、下划线"
                               name="field_name" datatype="*"/>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">排序</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control"
                               name="field_sort" value="0" datatype="n"/>
                    </div>
                    <label class="col-sm-2 control-label Validform_label">字段提示</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" placeholder="请输入字段提示"
                               name="tips" value=""/>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">验证规则</label>
                    <div class="col-sm-10">
                        {foreach $validRule as $key=>$value}
                        <label class="checkbox-inline i-checks">
                            <input type="checkbox" name="validate[]" value="{$key}" /> {$value}
                        </label>
                        {/foreach}
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">验证时机</label>
                    <div class="col-sm-10">
                        <label class="checkbox-inline i-checks">
                            <input type="radio" name="validate_scene" value="0" checked /> 不验证
                        </label>
                        <label class="checkbox-inline i-checks">
                            <input type="radio" name="validate_scene" value="1" /> 添加时
                        </label>
                        <label class="checkbox-inline i-checks">
                            <input type="radio" name="validate_scene" value="2" /> 编辑时
                        </label>
                        <label class="checkbox-inline i-checks">
                            <input type="radio" name="validate_scene" value="3" /> 全部
                        </label>
                    </div>
                </div>
                <div id="fieldTpl">

                </div>
                <div class="form-group">
                    <div class="col-sm-10 col-sm-offset-2">
                        <button class="btn btn-primary" id="btnSub" type="button">保存内容</button>
                        <a href="{:url('index',array('mid'=>$moudleInfo['mid']))}" class="btn btn-white">取消</a>
                        <span id="validError"></span>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    $(function () {
        iCheck();
        $("#fieldType").change(function () {
            var fieldType = $(this).val();
            $.post('{:url("getFieldTpl")}',{action: 'add', fieldType: fieldType},function(html){
                $("#fieldTpl").html(html);
            });
        });
        $("#fieldType").trigger("change"); //加载触发
        ajaxSubForm('#btnSub');
    })
</script>
{/block}